class Solution {
public:
    string addBinary(string a, string b) {
        reverse(a.begin(),a.end());
        reverse(b.begin(),b.end());
        int i=0,n=0;
        string ret;
        while(i<a.size()||i<b.size()||n)
        {
            if(i<a.size())
            n+=a[i]-'0';
              if(i<b.size())
            n+=b[i]-'0';
            ret.push_back(n%2+'0');
            n/=2;    
            i++;
        }
        reverse(ret.begin(),ret.end());
        return ret;
    }
};